import { defHttp } from '@/utils/http/axios';
import { GoodsParams, GoodsListGetResultModel, GoodsModel } from './model/goodsModel';

enum Api {
  GOODS_LIST = '/goods/page',
  GOODS_SAVE = '/goods/save',
  GOODS_DELETE = '/goods/del',
  GOODS_DETAIL = '/goods/detail',
  GOODS_SET_HOT = '/hot/set',
  GOODS_CANCEL_HOT = '/hot/cancel',
}

/**
 * @description: Get sample list value
 */

export const goodsListApi = (params: GoodsParams) =>
  defHttp.post<GoodsListGetResultModel>({
    url: Api.GOODS_LIST,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const goodsSaveApi = (params: GoodsParams) =>
  defHttp.post<number>({
    url: Api.GOODS_SAVE,
    params,
    headers: {
      // @ts-ignore
    },
  });

export const goodsDeleteApi = (params: GoodsParams) =>
  defHttp.post<number>({
    url: Api.GOODS_DELETE,
    params,
    headers: {
      // @ts-ignore
    },
  });

export const goodsDetailApi = (id: number) =>
  defHttp.get<GoodsModel>({
    url: Api.GOODS_DETAIL,
    params: { id: id },
    headers: {},
  });

export const setHotApi = (code: number, id: number) =>
  defHttp.postForm<number>({
    url: Api.GOODS_SET_HOT,
    params: { code: code, id: id },
    headers: {},
  });
export const cancelHotApi = (code: number, id: number) =>
  defHttp.postForm<number>({
    url: Api.GOODS_CANCEL_HOT,
    params: { code: code, id: id },
    headers: {},
  });
